$(function(){

    var t = null;
    t = setTimeout(time);
    function time()
    {
        clearTimeout(t);
        var dt = new Date();
        var y=dt.getYear()+1900;
        var mm=dt.getMonth()+1;
        var d=dt.getDate();
        var day=dt.getDay();
        var h=dt.getHours();
        var m=dt.getMinutes();
        var s=dt.getSeconds();
        if(h<10){h="0"+h;}
        if(m<10){m="0"+m;}
        if(s<10){s="0"+s;}
        document.getElementById("timeShow").innerHTML =  +y+"年"+mm+"月"+d+"日"+" "+h+":"+m+":"+s+"";
        t = setTimeout(time,1000); //设定定时器，循环执行           
    }
});

// 数据四舍五入 百分比
var rounding=function (count) {
    return parseFloat(Number(count*100).toFixed(2));
}
//  用于存储省级/市级内容
var provinceList,cityList
//  省列表生成
var cityDomList=function(data){
    console.log(data);
//      省份
provinceList=data.rows.provinceList;
//      市级
cityList=data.rows.cityList;
var str='';
for(var k in provinceList){
    str+='<option value="'+provinceList[k].code+'">'+provinceList[k].name+'</option>'
}
$('#province').append(str);
};
//  根据选择不同的省份显示不同的市级的option
$('#province').on('change',function(e){
    $('#city').children().remove();
    var province=e.target.value
    for(var k in cityList){
        if(province==cityList[k].province){
            var newCityList=cityList[k].cityList;
            var str='<option>选择市</option>';
            for(var i in newCityList){
                str+='<option value="'+newCityList[i].code+'">'+newCityList[i].name+'</option>'
            }
            $('#city').append(str);
        }
    }
});
var planInf= function (res) {
    console.log(res)
};
var cityechartInf= function (data) {
    console.log(data)
    var cityDate= data.rows.cityDate;
    var str='';
    for (var k in cityDate.chanyeGDP) {
        str+=
        '<div class="echother clearfix">'+
        '<span class="othertitle"><i class="ech_iconcyan"></i>'+cityDate.chanyeGDP[k].type+'</span>'+
        '<span class="moneydata">'+
        '<div class="increments">'+cityDate.chanyeGDP[k].increments+'</div><div>亿</div></span>'+
        '<span><div>同比<b>'+rounding(cityDate.chanyeGDP[k].MOM)+'%'+'</b></div><div>环比<b>'+rounding(cityDate.chanyeGDP[k].YOY)+'%'+'</b></div></span>'+
        '<span><i class="ech_up"></i><i class="ech_down"></i></span></div>'
    };
    if($('echother')){
        $('.echother').remove();
    }
// 显示生产总值
$('.echartother .echart').append(str);
var dataAxis=[];
var data=[];
for (var k in cityDate.hangyeGDP) {
    dataAxis.push(cityDate.hangyeGDP[k].type);
    data.push(cityDate.hangyeGDP[k].increments);
}
echarts.dispose(document.getElementById('echartGDP'));
    // 图表
    var myChartGDP = echarts.init(document.getElementById('echartGDP'));
    // var dataAxis =  ['大型交通','通勤','医院','教育','影院','KTV','酒吧','商超','通勤','医院','教育','影院','KTV','酒吧','商超','酒吧','商超'];
    // var data = [50, 40, 30, 50, 70, 30, 80, 50,50, 40, 30, 50, 70, 30, 80, 50, 50];
    var yMax = 100;
    var dataShadow = [];
    for (var i = 0; i < data.length; i++) {
        dataShadow.push(yMax);
    }
    var optionGDP = {
        backgroundColor: ['#2d3039'],
        textStyle:{
            color:['#fff'],
        },
        tooltip: {
            trigger: 'item',
        },
        xAxis: {
            data: dataAxis,
            axisLabel:{
                interval : 0,
                formatter:function(hangyetype)  
                {  
                    var hy='';
                    if (hangyetype.length>3) {
                        hy= hangyetype.substring(0,3)+"……";

                    }else{
                        hy=hangyetype;
                    }
                    return hy.split("").join("\n");
                }  
            },
            axisTick: {
                show: false
            },
        },
        yAxis: {
            show:false,
        },
        dataZoom: [
        {
            type: 'inside'
        }
        ],
        series: [
        { // For shadow
            type: 'bar',
            itemStyle: {
                normal: {color: 'rgba(57,61,73,0.4)'}
            },
            barGap:'-100%',
            barWidth: '30%',
            data: dataShadow,
            animation: false
        },
        {
            barWidth: '30%',
            type: 'bar',
            itemStyle: {
                normal: {
                    color: function (params){
                        if (params.dataIndex%2==0){
                            return '#1e80ff';
                        }else {
                            return '#d905ff';
                        }
                    }
                },
                emphasis:{
                }
            },
            data: data
        }
        ]
    };
        // 使用刚指定的配置项和数据显示图表。
        myChartGDP.setOption(optionGDP);

        echarts.dispose(document.getElementById('echartCPI'));
        var myChartCPI = echarts.init(document.getElementById('echartCPI'));
        var dataCPItype=[];
        var CPIMOM=[];
        var CPIYOY=[];
        for (var k in cityDate.CPI) {
            dataCPItype.push(cityDate.CPI[k].type);
            CPIMOM.push(rounding(cityDate.CPI[k].MOM));
            CPIYOY.push(rounding(cityDate.CPI[k].YOY));
        }
        ;
        // console.log(cityDate.CPI[1].MOM.toFixed(3));

var optionCPI = {
    backgroundColor: ['#2d3039'],
    textStyle:{
        color:['#fff'],
    },
    tooltip : {
        trigger: 'axis',
         axisPointer : {        // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow',        // 默认为直线，可选为：'line' | 'shadow'
                    shadowStyle:{
                        color:'#1683f6',
                        opacity:0.5,
                    }
                },
                 // formatter: ""
            },
            legend: {
                data:['同比','环比'],
                textStyle:{
                 color:'#fff'
             }
         },
         grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
        {
            type : 'value',
            splitLine :{
             show:false
         }
     }
     ],
     yAxis : [
     {
        type : 'category',
        data : dataCPItype
    }
    ],
    series : [
    {
        color: ['#458DD9'],
        name:'同比',
        type:'bar',
        stack: '年份',
        data: CPIYOY,
        label: {
         normal: {
          show: true,
          fontSize:10,
          position: 'insideLeft',
          formatter: '{c}%'
              // distance:'20',
              // distance:'100',
              //         rich:{
              //   width:100,
              // }
                      // distance:50,
                  }
              },
          },
          {
            color: ['#D8E6F6'],
            name:'环比',
            type:'bar',
            stack: '年份',
            data: CPIMOM,
            label: {
             normal: {
              show: true,
              position: 'insideRight',
              formatter: '{c}%'
                  // distance:'20',
              // rich:{
              //   width:100,
              // }
          }
      },
  }
  ]
}
myChartCPI.setOption(optionCPI);

var hangyetype= [];
var hangyeMOM=[];
for (var k in cityDate.hangye) {
    hangyetype.push(cityDate.hangye[k].tpye)
    hangyeMOM.push(cityDate.hangye[k].MOM)
}

echarts.dispose(document.getElementById('echartHY'));
var myChartHY = echarts.init(document.getElementById('echartHY'));
var optionHY = {
    backgroundColor: ['#2d3039'],
    textStyle:{
        color:['#fff'],
    },
    tooltip : {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: '#6a7985'
            }
        }
    },
    legend: {
        data:['同比','环比'],
        textStyle:{
            color:'#fff'
        }
    },
            // toolbox: {
            //  feature: {
            //      saveAsImage: {}
            //  }
            // },
            // grid: {
            //     left: '3%',
            //     right: '4%',
            //     bottom: '-100',
            //     containLabel: true
            // },
            xAxis : [
            {
                type : 'category',
                boundaryGap : false,
                data : hangyetype,
                axisLabel:{
                    interval : 0,
                    formatter:function(hangyetype)  
                    {  
                        var hy='';
                        if (hangyetype.length>3) {
                            hy= hangyetype.substring(0,3)+"……";

                        }else{
                            hy=hangyetype;
                        }
                        return hy.split("").join("\n");
                    }  
                },
            }
            ],
            yAxis : [
            {
                type : 'value',
                splitLine :{
                    show:false
                }
            }
            ],
            series : [
            {
                name:'同比',
                type:'line',
                stack: '行业',
                areaStyle: {normal: {}},
                symbol:"diamond",
                data:hangyeMOM,
                areaStyle:{
                    normal:{opacity:0.5}
                },
                itemStyle:{
                    normal:{color:'#1686fc'}
                }
            },
            {
               name:'环比',
               type:'line',
               stack: '行业',
               areaStyle: {normal: {}},
               symbol:"diamond",
               // data:,
               areaStyle:{
                normal:{opacity:0.5}
            },
            itemStyle:{
                normal:{color:'#e100ff'}

            }
        }
        ]
    };
    myChartHY.setOption(optionHY);

    var cityCharm=[];
    var CharmNum=[];
    for (var k in cityDate.cityCharm) {
        cityCharm.push(k);
        CharmNum.push(cityDate.cityCharm[k]);
    }
    echarts.dispose(document.getElementById('echartCharm'));
    var myChartCharm = echarts.init(document.getElementById('echartCharm'));
    var optionCharm = {
        backgroundColor: ['#2d3039'],
        textStyle:{
            color:['#fff'],
        },
            legend: {
                // data: ['参数一'],
                orient:'vertical',
                top:'112',
                right:'5',
                textStyle:{
                    color:'#fff'
                }
            },
            radar: [
            {
                indicator: [
                { text: cityCharm[0],mix:1000},
                { text: cityCharm[1],mix:1000},
                { text: cityCharm[2],mix:1000},
                { text: cityCharm[3],mix:1000},
                { text: cityCharm[4],mix:1000},
                { text: cityCharm[5],mix:1000}
                ],

                center: ['50%', '50%'],
                radius: 90,
                // startAngle: 90,
                splitNumber: 3,
                // shape: 'circle',
                name: {
                    formatter:'{value}',
                    textStyle: {
                        color:'#ffffff',
                    }
                },
                splitArea: {
                    areaStyle: {
                        color: [
                        'rgba(255, 255, 255, 0)'
                        ],
                        shadowColor: 'rgba(0, 0, 0, 0.3)',
                        shadowBlur: 10
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: 'rgba(60, 64, 76, 0.9)'
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: 'rgba(60, 64, 76, 0.9)'
                    }
                }
            }
            ],
            series: [
            {
                color:['#91c7ae','#749f83'],
                name: '雷达图',
                type: 'radar',
                itemStyle: {
                    normal: {
                        areaStyle: {
                            type: 'default',
                        }
                    }
                },
                data: [
                {
                    value:CharmNum,
                    itemStyle:{
                        normal:{color:'#e100ff'}
                    },
                    areaStyle:{
                        normal:{opacity:0.5},
                        emphasis: {opacity:0.7}
                    },
                    name: '参数一',
                    symbol: 'rect',
                    symbolSize: 1,
                },
        //         {
        //            value: [40, 40, 80, 90,100,60],
        //            itemStyle:{
        //             normal:{color:'#f3ea7c'}
        //         },
        //         areaStyle:{
        //             normal:{opacity:0.5},
        //             emphasis: {opacity:0.7}
        //         },
        //         name: '参数二',
        //         symbol: 'rect',
        //         symbolSize: 1,
        //     },
        //     {
        //        value: [20, 70, 80, 70,90,80],
        //        itemStyle:{
        //         normal:{color:'#fd6243'}
        //     },
        //     areaStyle:{
        //         normal:{opacity:0.5},
        //         emphasis: {opacity:0.7}
        //     },
        //     name: '参数三',
        //     symbol: 'rect',
        //     symbolSize: 1,

        // },
        ]
    }
    ]
}
         // 使用刚指定的配置项和数据显示图表。
         myChartCharm.setOption(optionCharm);

         var Brandname=[];
         var Brandnumber=[];
         for (var k in cityDate.BrandGroundNum) {
            Brandname.push(cityDate.BrandGroundNum[k].name)
            Brandnumber.push(cityDate.BrandGroundNum[k].number)
        }
        echarts.dispose(document.getElementById('echartBrand'));
        var myChartBrand = echarts.init(document.getElementById('echartBrand'));
        var optionBrand = {
           backgroundColor: ['#2d3039'],
           color:['#704ad0'],
           tooltip: {},
           textStyle:{
              color:['#fff'],
          },
            // legend: {
            //  data:['销量']
            // },

            xAxis: {
                data:  Brandname,
                axisLabel:{
                    interval : 0,
                    formatter:function(hangyetype)  
                    {  
                        var hy='';
                        if (hangyetype.length>3) {
                            hy= hangyetype.substring(0,3)+"…";

                        }else{
                            hy=hangyetype;
                        }
                        return hy.split("").join("\n");
                    }  
                    // interval : 0,
                    // formatter : function(params){
                    //     var newParamsName = "";
                    //     var paramsNameNumber = params.length;
                    //     var provideNumber = 4;
                    //     var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
                    //     if (paramsNameNumber > provideNumber) {
                    //         for (var p = 0; p < rowNumber; p++) {
                    //             var tempStr = "";
                    //             var start = p * provideNumber;
                    //             var end = start + provideNumber;
                    //             if (p == rowNumber - 1) {
                    //                 tempStr = params.substring(start, paramsNameNumber);
                    //             } else {
                    //                 tempStr = params.substring(start, end) + "\n";
                    //             }
                    //             newParamsName += tempStr;
                    //         }

                    //     } else {
                    //         newParamsName = params;
                    //     }
                    //     return newParamsName
                    // }
                }
            },
            yAxis: {
                show:false,
            },
            series: [{
                // name: '销量',
                type: 'bar',
                data: Brandnumber,
                barWidth: '30%',
            }]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChartBrand.setOption(optionBrand);



    };
//  页面登录获取对应的orderId的省市列表图表 方案数据
$(function(){
    var ajaxUrl=url;
    var cityListUrl=cityList;
    var cityechartUrl=cityechart;
    var mediaplanUrl=mediaplan;
    if(!sessionStorage.getItem('orderId')) {
        window.location.href='information.html';
        return false;
    }
    var orderId=sessionStorage.getItem('orderId');
    var orderIdData={
        orderId:orderId
    };
    var allInf={
        cityCode:sessionStorage.getItem('cityCode'),
        orderId:orderId
    };
    getData('post',ajaxUrl,mediaplanUrl,allInf,planInf);
    getData('post',ajaxUrl,cityListUrl,orderIdData,cityDomList)
    // 图表数据接口
    $('#city').on('change',function() {
        $('.city_info .a_blue').html($('#city option:selected').text());
        
        var cityCode = $('#city').val();
        console.log(cityCode);
        var cityData={
            cityCode:cityCode
        }
        sessionStorage.setItem('cityCode',cityCode);
        getData('post',ajaxUrl,cityechartUrl,cityData,cityechartInf);
    })
})


// var dataAxis = cityDate.hangyeGDP;



// 图表
